﻿using HealthcareSystem.API.Write.Application.Command.TeamCommand;
using HealthcareSystem.Domain.BasicSettings.Team;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.TeamCommandHandler
{
    /// <summary>
    /// 团队添加请求
    /// </summary>
    public class TeamCreatedCommandHandler : IRequestHandler<TeamCreatedCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<TeamTable> teamRep;

        public TeamCreatedCommandHandler(IBaseRepository<TeamTable> teamRep)
        {
            this.teamRep = teamRep;
        }

        public async Task<ApiResult<int>> Handle(TeamCreatedCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.添加成功;
            result.Message=ResultCode.添加成功.ToString();
            
            TeamTable team=new TeamTable();
            team.TeamName=request.TeamName; 
            team.ParentTeam=request.ParentTeam; 
            team.Charge=request.Charge;
            team.TeamTags=string.Join(",",request.TeamTags);
            team.TeamStatus=request.TeamStatus;
            team.Phone=request.Phone;
            team.TeamProfile=request.TeamProfile;
            team.IsDelete = false;
            await teamRep.AddAsync(team);
            return await Task.FromResult(result);



        }
    }
}
